package com.juicygames.framework.gamepart;

import java.util.ArrayList;
import java.util.List;

import com.juicygames.framework.action.EntityDestroyedAction;

public abstract class GameEntity extends GameComponent {
	
	private List<ActionForwarder> worldActionForwarders;
	
	public GameEntity() {
		super();
		entity = this;
	}
	
	public GameEntity getComponentEntity(GamePart part) {
		return this;
	}
	
	public void destroy() {
		super.destroy();
		
		if (worldActionForwarders != null) {
			for (ActionForwarder forwarder : worldActionForwarders) {
				forwarder.destroy();
			}
		}
		
		getWorld().handleAction(EntityDestroyedAction.getInstance(this));
	}

	public ActionForwarder groundHandler(GameHandler handler) {
		ActionForwarder forwarder = super.groundHandler(handler);
		
		if (forwarder != null) {
			
			if (worldActionForwarders == null) {
				worldActionForwarders = new ArrayList<ActionForwarder>();
			}
			
			worldActionForwarders.add(forwarder);
		}
		
		return forwarder;
	}
	
}

